<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"
	xmlns:hmrList="http://java.sun.com/jsf/composite/list"	
	xmlns:hmrSearch="http://java.sun.com/jsf/composite/search"	
	xmlns:hmrDetail="http://java.sun.com/jsf/composite/detail"	>

<cc:interface>
	<cc:attribute name="handler"				type="com.hemerasolutions.v2trainer.component.interfaces.search.TrainingSystemSearchCompInterface" required="true"/>
	<cc:attribute name="oncomplete"				type="java.lang.String" 	default="" 				required="false"/>
	<cc:attribute name="update"					type="java.lang.String" 	default="@none"			required="false"/>
	<cc:attribute name="importStepsMode"		type="java.lang.Boolean"	default="true"			required="false"/>		
	<cc:attribute name="onSearchComplete"		type="java.lang.String" 	default="" 				required="false"/>
	<cc:attribute name="searchUpdate"			type="java.lang.String" 	default="" 				required="false"/>
	<cc:attribute name="showResultsPanel"		type="java.lang.Boolean"	default="false"			required="false"/>				
			
</cc:interface>

<cc:implementation>
	<span id="#{cc.clientId}" >
		<h:form id="findTrainingSystemForm" prependId="false" style="width:500px">
			<h:panelGrid columns="2">
				<h:outputLabel 	value="#{msgs.Name} :" 	/>
				<p:inputText	value="#{ cc.attrs.handler.trainingSystemFindByName}" 			maxlength="50" 	size="20" />

				<h:outputLabel 	value="#{msgs.Description} :" />
				<p:inputText	value="#{ cc.attrs.handler.trainingSystemFindByDescription}"	maxlength="100" 	size="45" />
 

				<h:outputLabel 	value="#{msgs.Obs} :"/>
				<p:inputText	value="#{ cc.attrs.handler.trainingSystemFindByObs}"					maxlength="100" 	size="45" />

				<h:outputText value="#{msgs.ModalityTypes}" style="white-space: nowrap;"/>
				<p:selectCheckboxMenu value="#{cc.attrs.handler.findTrainingSystemByTrainingTypes}" converter="#{genericConverter}"   
					filter="true" panelStyle="width:220px" label="#{msgs.ModalityTypes}" >
	            	<f:selectItems value="#{cc.attrs.handler.fullTrainingTypes}"  var="trainingType" itemLabel="#{msgs[trainingType.name]}" itemValue="#{trainingType}" />
					<p:ajax event="toggleSelect"	listener="#{cc.attrs.handler.changeFullTrainingTypesAll}" update="tsmodalitySelect"  />
					<p:ajax listener="#{cc.attrs.handler.changeFullTrainingTypes}" update="tsmodalitySelect"  />
				</p:selectCheckboxMenu>

				<h:outputText  value="#{msgs.Modalitys}" />
				<p:selectCheckboxMenu id="tsmodalitySelect" value="#{cc.attrs.handler.findTrainingSystemByModalitys}" converter="#{genericConverter}" 
					filter="true" panelStyle="width:220px" label="#{msgs.Modalitys}" disabled="#{empty cc.attrs.handler.fullModalitys }" >
					<p:ajax event="toggleSelect"	listener="#{cc.attrs.handler.changeFullModalitysAll}" update="tsmodalitySelect"  />
	            	<f:selectItems value="#{cc.attrs.handler.fullModalitys}"  var="modality" itemLabel="#{modality.name}" itemValue="#{modality}" />
				</p:selectCheckboxMenu>		

				<h:outputLabel	value="#{ msgs.CreatedAt} :" />
				<h:column>
					<p:calendar		value="#{cc.attrs.handler.trainingSystemBegCreatedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                	<p:calendar		value="#{cc.attrs.handler.trainingSystemEndCreatedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>


				<h:outputLabel	value="#{ msgs.ChangedAt} :" />
				<h:column>
					<p:calendar		value="#{cc.attrs.handler.trainingSystemBegChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                    <p:calendar		value="#{cc.attrs.handler.trainingSystemEndChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>

				<h:outputLabel value="#{ msgs.Status}  :" />
				<p:selectOneRadio value="#{ cc.attrs.handler.trainingSystemFindByStatus}">
					<f:selectItem itemLabel="#{ msgs.Active}" 		itemValue="true" />
					<f:selectItem itemLabel="#{ msgs.Inactive}" 	itemValue="false" />
				</p:selectOneRadio>
			</h:panelGrid>
				
			<p:commandButton value="#{ msgs.Search}"	actionListener="#{cc.attrs.handler.searchTrainingSystems}" update=" #{cc.attrs.searchUpdate}, :growl, panelFoundTrainingSystemsTable" 	
				oncomplete="#{cc.attrs.onSearchComplete}" icon=" ui-icon-search"  process="@form" />
			<p:commandButton value="#{ msgs.Clear}"		type="button"	icon="ui-icon-clean">
				 <p:ajax update="findTrainingSystemForm" resetValues="true" />  	
			</p:commandButton>
			
			<p:outputPanel id="panelFoundTrainingSystemsTable" layout="block" rendered="#{cc.attrs.showResultsPanel}" >
				<p:spacer height="20" rendered="#{not empty cc.attrs.handler.foundTrainingSystems }" />
				<p:dataTable id="tblTrainingSystem"  value="#{cc.attrs.handler.foundTrainingSystems}" var="trainingSystem" paginator="true" rendered="#{not empty cc.attrs.handler.foundTrainingSystems }"
					paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8">
					<p:columnGroup type="header">  
						<p:row>
							<p:column colspan="5">
								<f:facet name="header">
									<h:outputText value="#{msgs.TrainingSystems}" />
								</f:facet>
							</p:column>
						</p:row>
						<p:row>
							<p:column	colspan="4"  style="white-space: nowrap;"  >
								<f:facet name="header">
									<h:outputText value="#{msgs.Name}"/>
								</f:facet>
							</p:column>
							<p:column	colspan="1" >
								<f:facet name="header">
									<h:outputText value="#{msgs.Description}"/>
								</f:facet>
							</p:column>
						</p:row>	
					</p:columnGroup>
					<p:column colspan="2" style="white-space: nowrap;">
						<h:outputText value="#{trainingSystem.name}"  />
					</p:column>
					<p:column colspan="1" styleClass="ui-table-button-row" >
						<p:commandButton title="#{msgs.View}" icon="ui-icon-search" action="#{cc.attrs.handler.toViewTrainingSystem}" 	
							update=":#{cc.clientId}:modalTrainingSystemView" oncomplete="wmodalTrainingSystemView_#{cc.id}.show();"  styleClass="ui-table-button">
							<f:setPropertyActionListener target="#{cc.attrs.handler.trainingSystem}" 	value="#{trainingSystem}"/>
						</p:commandButton>	
					</p:column>
					<p:column colspan="1" styleClass="ui-table-button-row" > 
						<p:commandButton title="#{msgs.Import}" icon="ui-icon-plus" action="#{cc.attrs.handler.toConfigTrainingSystem}"  rendered="#{cc.attrs.importStepsMode}" 	  
							update="@form:panelFoundTrainingSystemsTable,:#{cc.clientId}:modalImportTS" oncomplete="wmodalImportTS_#{cc.id}.show();"  styleClass="ui-table-button" >
							<f:setPropertyActionListener target="#{cc.attrs.handler.trainingSystem}" 	value="#{trainingSystem}"/>
						</p:commandButton>
						
						<p:commandButton title="#{msgs.Add}" icon="ui-icon-plus" action="#{cc.attrs.handler.addTrainingSystem}"  	rendered="#{not cc.attrs.importStepsMode}"
							update="#{cc.attrs.update},@form:panelFoundTrainingSystemsTable" oncomplete="#{cc.attrs.oncomplete}"  styleClass="ui-table-button" >
							<f:setPropertyActionListener target="#{cc.attrs.handler.selTrainingSystem}" 	value="#{trainingSystem}"/>
						</p:commandButton>

					</p:column>		
					<p:column colspan="1" style="white-space: nowrap;width:300px;max-width:300px;">
						<h:outputText value="#{trainingSystem.description}"  />
					</p:column>
				</p:dataTable>
			</p:outputPanel>	
		</h:form>		
	</span>



	<p:dialog id="modalTrainingSystemView" header="#{msgs.TrainingSystem}: #{cc.attrs.handler.selTrainingSystem.name}" appendTo="@(body)" modal="true" widgetVar="wmodalTrainingSystemView_#{cc.id}" >
		<hmrDetail:trainingSystemDetails handler="#{cc.attrs.handler.tsDetails}"/>
		<div align="left"   > 
			<p:commandButton type="button" value="#{msgs.Cancel}"		icon="ui-icon-cancel" onclick="wmodalTrainingSystemView_#{cc.id}.hide()"/>
		</div>
	</p:dialog>	


	<p:dialog id="modalImportTS" header=" #{msgs.Import} #{msgs.TrainingSystem}" position="top" appendTo="@(body)" modal="true" widgetVar="wmodalImportTS_#{cc.id}">
		<p:tabView id="tsAddTabView" style="min-width:740px;max-width:740px"  >
			<p:tab title="#{msgs.Exercises}">
				<h:form prependId="false">
					<p:dataTable value="#{cc.attrs.handler.templateExercises}" var="templateExercise" paginator="true"  style="min-width:200px"
			 			paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8" emptyMessage="#{msgs.NoExercisesToDefine}">   
						<p:columnGroup type="header" >  
							<p:row>
								<p:column colspan="6" style="text-align:center;">
									<f:facet name="header">
										<h:outputText value="#{msgs.TrainingSystemExercises}" />
									</f:facet>
								</p:column>
							</p:row>
							<p:row>
								<p:column	colspan="2" >
									<f:facet name="header"> 
											<h:outputText value="#{msgs.Name}" style="padding-top:4px"/>
									</f:facet>
								</p:column>
								<p:column	colspan="1" >
									<f:facet name="header"> 
											<h:outputText value="#{msgs.Modality}" style="padding-top:4px"/>
									</f:facet>
								</p:column>
							</p:row>	 
						</p:columnGroup>

						<p:column colspan="1" headerText="#{msgs.Name}" >
							<h:outputText value="#{templateExercise.variation}" />
						</p:column>
			
						<p:column colspan="1" styleClass="ui-table-button-row" >
							<p:commandButton action="#{cc.attrs.handler.toConfigTemplate}"  title="#{msgs.Define}" icon="ui-icon-help" 
								update=":#{cc.clientId}:modalSetTemplateSource" oncomplete="wmodalSetTemplateSource_#{cc.id}.show()"  styleClass="ui-table-button">
								<f:setPropertyActionListener target="#{cc.attrs.handler.selTemplate}" value="#{templateExercise}"/>
							</p:commandButton>
						</p:column>
						<p:column colspan="1" headerText="#{msgs.Name}" >
							<h:outputText value="#{templateExercise.modality.name}" />
						</p:column>
					</p:dataTable>					
					<p:spacer width="0" height="10" />
					
					<p:commandButton title="#{msgs.Add}" 		value="#{msgs.Add}"  	process="@form"		action="#{cc.attrs.handler.transferSteps}"
						oncomplete="wmodalImportTS_#{cc.id}.hide();" />
					<p:commandButton value="#{msgs.Cancel }" onclick="wmodalImportTS_#{cc.id}.hide();"	type="button" />
				</h:form>		

			</p:tab>
			<p:tab title="#{msgs.Preview}"> 
				<h:form prependId="false">
					<hmrList:stepListComp handler="#{cc.attrs.handler.stepListHandler}" enabled="true" /> 
				</h:form>	
			</p:tab>
		</p:tabView>

	</p:dialog>
	
 
 	<p:dialog id="modalSetTemplateSource" header="#{msgs.DefineTemplateExercise}" appendTo="@(body)" modal="true" widgetVar="wmodalSetTemplateSource_#{cc.id}">
		<p:accordionPanel id="searchSource">
			<p:tab title="#{msgs.Exercises}">
				<hmrSearch:exerciseSearch handler="#{cc.attrs.handler.exerciseSearchComp}" oncomplete="wmodalSetTemplateSource_#{cc.id}.hide();wmodalImportTS_#{cc.id}.show();" 
					update=":#{cc.clientId}:modalImportTS"/>
			</p:tab>
			<p:tab title="#{msgs.ExerciseGroups}">
				<hmrSearch:exerciseGroupSearch handler="#{cc.attrs.handler.exerciseGroupSearchComp}" oncomplete="wmodalSetTemplateSource_#{cc.id}.hide();;wmodalImportTS_#{cc.id}.show();"
					update=":#{cc.clientId}:modalImportTS" />
			</p:tab>
		</p:accordionPanel>
 	</p:dialog>


</cc:implementation>
</html>	